package com.fs.procure.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.core.vo.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.common.util.page.PageUtils;
import com.fs.procure.pojo.Insto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.procure.service.IInstoService;


/**
 * 入库申请Controller
 * 
 * @author lan
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/procure/insto")
public class InstoController extends BaseController
{
    @Autowired
    private IInstoService instoService;

    /**
     * 查询入库申请列表
     */
    @PreAuthorize("@ss.hasPermi('procure:insto:list')")
    @GetMapping("/list")
    public TableDataInfo list(Insto insto)
    {
        PageUtils.startPage();
        List<Insto> list = instoService.selectInstoList(insto);
        Page<Insto> page=new Page<>();
        page.setRecords(list);
        page.setTotal(list.size());
        return getDataTable(page);
    }

//    /**
//     * 导出入库申请列表
//     */
//    @PreAuthorize("@ss.hasPermi('procure:insto:export')")
//    @Log(title = "入库申请", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Insto insto)
//    {
//        List<Insto> list = instoService.selectInstoList(insto);
//    }

    /**
     * 获取入库申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('procure:insto:query')")
    @GetMapping(value = "/{instoId}")
    public AjaxResult getInfo(@PathVariable("instoId") Long instoId)
    {
        Insto insto = instoService.selectInstoByInstoId(instoId);
        return insto!=null?AjaxResult.success("",insto):AjaxResult.error("");
    }

    /**
     * 新增入库申请
     */
    @PreAuthorize("@ss.hasPermi('procure:insto:add')")
    @Log(title = "入库申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Insto insto)
    {

        int i = instoService.insertInsto(insto);
        return i>0? AjaxResult.success():AjaxResult.error();
    }

    /**
     * 修改入库申请
     */
    @PreAuthorize("@ss.hasPermi('procure:insto:edit')")
    @Log(title = "入库申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Insto insto)
    {
        int i = instoService.updateInsto(insto);
        return i>0?AjaxResult.success():AjaxResult.error();
    }

    /**
     * 删除入库申请
     */
    @PreAuthorize("@ss.hasPermi('procure:insto:remove')")
    @Log(title = "入库申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instoIds}")
    public AjaxResult remove(@PathVariable Long[] instoIds)
    {
        int i = instoService.deleteInstoByInstoIds(instoIds);
        return i>0?AjaxResult.success():AjaxResult.error();
    }
}
